/***************************************************************************
 *   Copyright (C) 2007 - 2009 by Andreas Theofilu                         *
 *   andreas@theosys.at                                                    *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation version 3 of the License.                *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#include "managefile.h"

#include <kmessagebox.h>

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>

manageFile::manageFile ()
{
	fname = 0;
}

manageFile::manageFile(const char *name)
{
	fname = name;
	setFileName(name);
}

manageFile::~manageFile()
{
	destroy();
}

void manageFile::destroy()
{
	if (spw.handle() != -1)
	   spw.close();

	fname = 0;
}

int manageFile::setFileName(const char *name)
{
	if (name)
	{
	   if (spw.handle() != -1)
	      spw.close();

	   fname = name;
	   spw.setFileName(QString(name));

	   if (spw.open(QIODevice::ReadOnly) == false)
	      return -1;

	   return spw.handle();
	}

	return -1;
}

garmin_data *manageFile::readFile()
{
	return garmin_load (fname);
}
